package com.jielin.handling.controller.leaveregion;

import com.alibaba.fastjson.JSONObject;
import com.jielin.handling.Annotation.MyPower;
import com.jielin.handling.bean.AppResult;
import com.jielin.handling.entity.leaveregion.LeaveRegion;
import com.jielin.handling.service.leaveregion.LeaveregionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by wangjienice on 2019/3/20.
 */
@RestController
@RequestMapping("/Leaveregion/")
@Slf4j
@MyPower(name = "嫌疑人离开办案区模块", url = "/Leaveregion")
@CrossOrigin
public class LeaveregionController {
	@Autowired
	LeaveregionService leaveregionService;

	/**
	 * 嫌疑人离开
	 */
	@MyPower(name = "嫌疑人离开", url = "/addLeaveregion")
	@RequestMapping("addLeaveregion")
	public AppResult addLeaveregion(@RequestBody LeaveRegion leaveRegion) {
		AppResult appResult = new AppResult();
		JSONObject date = new JSONObject();
		log.info("leaveRegion:{}", JSONObject.toJSONString(leaveRegion));
		int value = leaveregionService.addLeaveregion(leaveRegion);
		if (value ==1) {
			date.put("value", 1);
			appResult.setCode(200);
			appResult.setMsg("添加嫌疑人离开记录成功!");
			appResult.setData(date);
		} else if (value == 2){
			date.put("value", 2);
			appResult.setCode(-100);
			appResult.setMsg("请填写嫌疑人的基本信息");
			appResult.setData(date);
		}else {
			date.put("value", 0);
			appResult.setCode(-1);
			appResult.setMsg("添加嫌疑人离开记录失败!");
			appResult.setData(date);
		}
		return appResult;

    }

	/**
	 * 查询嫌疑人离开办案区信息
	 *
	 * @param suspectId 嫌疑人id
	 * @return
	 */
	@MyPower(name = "查询嫌疑人离开办案区信息", url = "/selelctLeaveregion", isPublic = true)
	@RequestMapping("selelctLeaveregion")
	public AppResult selelctLeaveregion(String suspectId) {
		AppResult appResult = new AppResult();
		JSONObject date = new JSONObject();
		log.info("suspectId:{}", JSONObject.toJSONString(suspectId));
		LeaveRegion value = leaveregionService.selelctLeaveregion(suspectId);
		date.put("value", value);
		appResult.setCode(200);
		appResult.setMsg("查询嫌疑人离开办案区信息成功!");
		appResult.setData(date);
		return appResult;

	}
}
